import {SERVER} from "../configs";


export class  user{
    name : string="";
    password:string="";

     setName( name:string){
         this.name=name
     }

     setPassword(password:string){
         this.password=password
     }
     getName(){
         return this.name
     }
     getPassword(){
         return this.password
     }
     login():Promise<boolean>{
      return  fetch("http://localhost:8081/login",{
            method:"POST",
            headers:{
                "Content-Type":"application/json"
            },
            body:JSON.stringify({
                name:this.name,
                password:this.password
            })
        }).
      then((res)=>{
            if(res.status===200){
                {
                    console.log('登录成功')
                    return true

                }
            }else{
                console.log('hello')
                return false
            }
        })
     }
     register():Promise<boolean>{
         // return true;
        return  fetch(SERVER+"/registry",{
             method:"POST",
             headers:{
                 "Content-Type":"application/json"
             },
             body:JSON.stringify({
                 name:this.name,
                 password:this.password
             })
         }).then((res)=>{
             console.log(res.status)
             if(res.status===200){
                 return true
             }else{
                 return false
             }
         })
     }


}

export default user
